/******************************************************************************/
/* OV5647 寄存器SCCB接口读写函数*/
/**/
/******************************************************************************/
#include "fx2.h"
#include "fx2regs.h"
#include "sccb.h"
void OV5647_reg_write(WORD regaddr, BYTE value)
{
	
		
	I2CS |= bmSTART;
	I2DAT = OV5647_slave_id_write;
	while (!(I2CS & bmDONE));  		// wait for a data transfer done

	I2DAT = regaddr>>8;				// write regaddr MSB 
	while (!(I2CS & bmDONE));  		
	
	I2DAT = regaddr;
	while (!(I2CS & bmDONE));  		// write regaddr LSB
					
	I2DAT = value;
	while (!(I2CS & bmDONE));  	
					

	I2CS |= bmSTOP;
	while (I2CS & bmSTOP);      	// wait for the 'stop' condition is generated.

}

BYTE OV5647_reg_read(WORD regaddr)
{
	BYTE value;
	

	I2CS |= bmSTART;
	I2DAT = OV5647_slave_id_write;	// write device adderss
	while (!(I2CS & bmDONE));  		// wait for a data transfer done

	I2DAT = regaddr>>8;				// regaddr MSB
	while (!(I2CS & bmDONE));  		
	
	I2DAT = regaddr;
	while (!(I2CS & bmDONE));  		// regaddr LSB
 	
	I2CS |= bmSTART;		    				
	I2DAT =OV5647_slave_id_read;
	while (!(I2CS & bmDONE));  			
	
	value = I2DAT ;         				
	I2CS = bmLASTRD;
	while (!(I2CS & bmDONE));  		
	
	I2CS |=bmSTOP;
	value = I2DAT;    
	while (I2CS & bmSTOP);      	// wait for the 'stop' condition is generated.
	
	return value;
}